package jse.io;

import org.junit.Test;

import java.io.*;

/**
 * @desc 输入流及输出流 ：针对内存而言，输入流-：文件到程序，输出流：程序到文件
 * @author kanggw
 * @create 2016 08 11 11:56
 */
public class TestInAndOutStream {

    public void testWriter(File file) {

        try {
            FileOutputStream os = new FileOutputStream(file);
            try {
                os.write('a');
                os.write('b');
                os.write('c');
                os.write('d');
                os.write('f');
                os.write('a');
            } catch (IOException e) {
                e.printStackTrace();
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }

    }

    public void testRead(File file) {

        try {
            FileInputStream is = new FileInputStream(file);
            for (int i = 0;i< is.toString().length();i++) {
                System.out.println(is.read());
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }

    @Test
    public void test() {
        String path = "c:" + File.separator + "test"+File.separator+"aaa.txt";
        File file = new File(path);
//        testWriter(file);
          testRead(file);
    }
}
